/**
 * 
 * gislin
 * 2017年5月4日
 */
package com.szholly.pro.watergas_server.common.util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import com.szholly.data.general.GlobalParameter;
import com.szholly.data.general.RowBase;
import com.szholly.pro.watergas_server.common.data.DataUtil;
import com.szholly.pro.watergas_server.common.data.ParameterSqlModel;
import com.szholly.pro.watergas_server.common.data.SqlUtil;
import com.szholly.pro.watergas_server.ps.monitor.MonitorDataModel;
import com.szholly.pro.watergas_server.ps.monitor.MonitorDataService;
import com.szholly.pro.watergas_server.ps.monitor.MonitorDataType;
import com.szholly.pro.watergas_server.ps.monitor.PollutantsModel;
import org.springframework.stereotype.Service;

/**
 * @author gislin
 * 2017年5月4日
 */
@Service
public class MonitorDataUtil {

	/**
	 * 获取站点报警阈值
	 * @param wwtp_id
	 * @param flow_type
	 * @param station_id
	 * @param mn TODO
	 * @param parms TODO
	 * @return
	 */
	public List<PollutantsModel> getPollInfo(String mn, String[] parms) {
	
		List<PollutantsModel> pollInfos = new ArrayList<>();
		
		for(String poll : parms){
			PollutantsModel pollModel = new PollutantsModel();
			
			String pollName = RedisHelper.getInstance().translationDictValue("MONITOR_PARAM", poll);
			pollModel.setName(pollName);
	
			try {
				Double down = RedisHelper.getInstance().getPollAlarmDown(mn, poll);
				pollModel.setDown(down);
				
			} catch (Exception e) {
				System.out.println(e);
			}
			
			try {
				Double up = RedisHelper.getInstance().getPollAlarmUp(mn, poll);
				pollModel.setUp(up);
			} catch (Exception e) {
				System.out.println(e);
			}
			
			String unit = RedisHelper.getInstance().translationDictUnit("MONITOR_PARAM", poll);
			pollModel.setUnit(unit);
			pollModel.setPollCode(poll);
			pollInfos.add(pollModel);
			
		}
	
		return pollInfos;
	}
	
	/**
	 * 清理空数据，避免freeMark中循环报错
	 * gislin
	 * 2017年5月5日
	 * @param data
	 * @return
	 */
	public List<RowBase> clearMonitorData(List<RowBase> data){
		
		List<RowBase> result = new ArrayList<>();
		
		for(RowBase row : data){
			if(row != null){
				result.add(row);
			}
		}
		
		return result;
	}

	/**
	 * 废水、废气生成最大值最小值和均值
	 * @param historyData
	 * @param dataModel TODO
	 * @param parms
	 * @param dataFields
	 * @return 返回list，顺序为：最小值，最大值，平均值
	 */
	public MonitorDataModel generaMinMaxAvgGas(MonitorDataModel dataModel, String[] parms, String[] dataFields, String waterType){
		RowBase minRow = new RowBase();
		RowBase maxRow = new RowBase();
		RowBase avgRow = new RowBase();
		RowBase emissionsRow = new RowBase();
		List<RowBase> result = new ArrayList<>();
		List<Double> valueList = new ArrayList<>();
		List<RowBase> historyData = dataModel.getData();
		
		for(String pollCode : parms){
			
			for(String field : dataFields){
				
				String key = (field + "_" + pollCode).toUpperCase();
				double totalValue = 0;
				
				//累积流量AVG_B01TOTAL
				String totalKey=(field+"_B01TOTAL").toUpperCase();
				double emissionsValue = 0;
				
				valueList.clear();
				
				for(RowBase row : historyData){
					Double value = row.getSafeDouble(key);
					totalValue += value;
					valueList.add(value);
					//排放量计算
					Double b01totalValue = row.getSafeDouble(totalKey);
					java.text.DecimalFormat dv = new java.text.DecimalFormat("##.00");
					Double evalue=Double.valueOf(dv.format(value));
					b01totalValue =Double.valueOf(dv.format(b01totalValue));
					if("B01TOTAL".equals(pollCode)){
						emissionsValue+=b01totalValue;
					}
					else{
						emissionsValue+=evalue*b01totalValue/1000;//转成kg为单位
					}
					
				}
				
				if(valueList != null && valueList.size() > 0){
					if(waterType.equals("2")||waterType.equals("4")){
						List<Double> dataList = new ArrayList<>();
						dataList.clear();
						Double ValueAvg=0.0;
						for(Double row:valueList){
							if(row>0&&row!=null){
								dataList.add(row);
								ValueAvg=+ValueAvg+row;
							}
						} 
						if(dataList != null && dataList.size() > 0){
							minRow.setValue(key, Collections.min(dataList));
							maxRow.setValue(key, Collections.max(dataList));
							avgRow.setValue(key, ValueAvg/dataList.size());
						}						
					}else{
						minRow.setValue(key, Collections.min(valueList));
						maxRow.setValue(key, Collections.max(valueList));
						avgRow.setValue(key, totalValue/historyData.size());
					}	
					//排放量组装
					if("AVG".equals(field)){
						if("B01".equals(pollCode)||"001".equals(pollCode)||"phtem".equals(pollCode)){
							
						}
						else{
							java.text.DecimalFormat df = new java.text.DecimalFormat("##.00");
							if("B01TOTAL".equals(pollCode)){
								emissionsRow.setValue("EMISSIONS_"+pollCode,df.format(emissionsValue)+"(吨)" );
							}
							else{
								emissionsRow.setValue("EMISSIONS_"+pollCode,df.format(emissionsValue)+"(kg)" );
							}
							
						}
							
					}
					else{
						emissionsRow.setValue(key+"_EMISSIONS", emissionsValue);	
					}	
					
				}
			}
		}
		
		minRow.setValue("DATATIME", "最小值");
		maxRow.setValue("DATATIME", "最大值");
		avgRow.setValue("DATATIME", "平均值");
		emissionsRow.setValue("DATATIME", "排放量");
		
		result.add(minRow);
		result.add(maxRow);
		result.add(avgRow);
		result.add(emissionsRow);
		
		dataModel.setMinData(minRow);
		dataModel.setMaxData(maxRow);
		dataModel.setAvgData(avgRow);
		dataModel.setEmissionsData(emissionsRow);
		
		return dataModel;
	}
	
	/**
	 * 生成最大值最小值和均值
	 * @param historyData
	 * @param dataModel TODO
	 * @param parms
	 * @param dataFields
	 * @return 返回list，顺序为：最小值，最大值，平均值
	 */
	public MonitorDataModel generaMinMaxAvg(MonitorDataModel dataModel, String[] parms, String[] dataFields,String waterType){
		RowBase minRow = new RowBase();
		RowBase maxRow = new RowBase();
		RowBase avgRow = new RowBase();
		RowBase emissionsRow = new RowBase();
		List<RowBase> result = new ArrayList<>();
		List<Double> valueList = new ArrayList<>();
		List<RowBase> historyData = dataModel.getData();
		
		for(String pollCode : parms){
			
			for(String field : dataFields){
				
				String key = (field + "_" + pollCode).toUpperCase();
				double totalValue = 0;
				
				//累积流量AVG_B01TOTAL
				String totalKey=(field+"_B01TOTAL").toUpperCase();
				double emissionsValue = 0;
				
				valueList.clear();
				
				for(RowBase row : historyData){
					Double value = row.getSafeDouble(key);
					totalValue += value;
					valueList.add(value);
					//排放量计算
					Double b01totalValue = row.getSafeDouble(totalKey);
					java.text.DecimalFormat dv = new java.text.DecimalFormat("#########0.00");
					Double evalue=Double.valueOf(dv.format(value));
					b01totalValue =Double.valueOf(dv.format(b01totalValue));
					if("B01TOTAL".equals(pollCode)){
						emissionsValue+=b01totalValue;
					}
					else{
						emissionsValue+=evalue*b01totalValue/1000;//转成kg为单位
					}
					
				}
				
				if(valueList != null && valueList.size() > 0){
					if(waterType.equals("2")||waterType.equals("4")){
						List<Double> dataList = new ArrayList<>();
						dataList.clear();
						Double ValueAvg=0.0;
						for(Double row:valueList){
							if(row>0&&row!=null){
								dataList.add(row);
								ValueAvg=+ValueAvg+row;
							}
						} 
						if(dataList != null && dataList.size() > 0){
							minRow.setValue(key, Collections.min(dataList));
							maxRow.setValue(key, Collections.max(dataList));
							avgRow.setValue(key, ValueAvg/dataList.size());
						}						
					}else{
						minRow.setValue(key, Collections.min(valueList));
						maxRow.setValue(key, Collections.max(valueList));
						avgRow.setValue(key, totalValue/historyData.size());
					}	
					//排放量组装
					if("AVG".equals(field)){
						if("B01".equals(pollCode)||"001".equals(pollCode)||"phtem".equals(pollCode)){
							
						}
						else{
							java.text.DecimalFormat df = new java.text.DecimalFormat("#########0.00");
							if("B01TOTAL".equals(pollCode)){
								emissionsRow.setValue("EMISSIONS_"+pollCode,df.format(emissionsValue)+"(吨)" );
							}
							else{
								emissionsRow.setValue("EMISSIONS_"+pollCode,df.format(emissionsValue)+"(kg)" );
							}
							
						}
							
					}
					else{
						emissionsRow.setValue(key+"_EMISSIONS", emissionsValue);	
					}	
					
				}
			}
		}
		
		minRow.setValue("DATATIME", "最小值");
		maxRow.setValue("DATATIME", "最大值");
		avgRow.setValue("DATATIME", "平均值");
		emissionsRow.setValue("DATATIME", "排放量");
		
		result.add(minRow);
		result.add(maxRow);
		result.add(avgRow);
		result.add(emissionsRow);
		
		dataModel.setMinData(minRow);
		dataModel.setMaxData(maxRow);
		dataModel.setAvgData(avgRow);
		dataModel.setEmissionsData(emissionsRow);
		
		return dataModel;
	}

	/**
	 * 获取分项类别行,综合水质类别，主要污染物
	 * @param avgRow
	 * @param monitorDataService TODO
	 * @param dataModel TODO
	 * @param fieldPrefix
	 * @param parms
	 * @return 返回一个list，里面的顺序是：分项类别行,综合水质类别，主要污染物
	 */
	public MonitorDataModel generaWaterStandardInfo(MonitorDataService monitorDataService, MonitorDataModel dataModel, String fieldPrefix, String[] parms){
		
		RowBase waterStandardRow = new RowBase();
		RowBase totalWaterStandardRow = new RowBase();
		RowBase mainPollRow = new RowBase();
		
		RowBase avgRow = dataModel.getAvgData();
		
		List<RowBase> result = new ArrayList<>();
		
		int maxQualityClass = 0;//最大的水质类别，用于生成综合水质类别
		String maxQualityClassDesc = ""; //综合水质类别描述
		String mainPollText = "";
		
		List<RowBase> standardRows = monitorDataService.getWaterQualityStandards("SURFACE_WATER");
		
		for(String pollCode : parms){
			String field = (fieldPrefix + "_" + pollCode).toUpperCase();
			
			double value = avgRow.getSafeDouble(field);
			
			for(RowBase standardItem:standardRows){
				if(!(standardItem.getSafeString("ITEM")).equals(pollCode)){
					continue;
				}
				
				if(value>=standardItem.getSafeDouble("MINIMUM") && value<=standardItem.getSafeDouble("MAXIMUM")){
					int qualityClass = standardItem.getSafeInt("QUALITY_CLASS");
					String qualityClassDesc;
					
					if(qualityClass==1){
						qualityClassDesc = "I";
					}else if(qualityClass==2){
						qualityClassDesc = "II";
					}else if(qualityClass==3){
						qualityClassDesc = "III";
					}else if(qualityClass==4){
						qualityClassDesc = "IV";
					}else if(qualityClass==5){
						qualityClassDesc = "V";
					}
					else{
						qualityClassDesc = "劣V";
					}
					
					if(qualityClass > maxQualityClass){
						maxQualityClass = qualityClass;
						maxQualityClassDesc = qualityClassDesc;
					}
					
					if(qualityClass > 3){
						String pollName = RedisHelper.getInstance().translationDictValue("MONITOR_PARAM",pollCode);
						mainPollText += pollName+",";
					}
					
					waterStandardRow.setValue(field, qualityClassDesc);
				}
			}
		}
		
		totalWaterStandardRow.setValue("value", maxQualityClassDesc);
		mainPollRow.setValue("value", mainPollText);
		
		totalWaterStandardRow.setValue("DATATIME", "综合水质类别");
		waterStandardRow.setValue("DATATIME", "分类类别");
		mainPollRow.setValue("DATATIME", "主要污染物");
		
		result.add(waterStandardRow);
		result.add(totalWaterStandardRow);
		result.add(mainPollRow);
		
		dataModel.setTotalWaterStandard(totalWaterStandardRow);
		dataModel.setWaterStandard(waterStandardRow);
		dataModel.setMainPoll(mainPollRow);
		
		return dataModel;
	}

	/**
	 * 给报表添加报警信息
	 * gislin
	 * 2016年8月5日
	 * @param list 列表数据
	 * @param parms 要分析的污染物集合
	 * @param mn 设备编号
	 * @param dataType RTD AVG COU
	 * @return
	 */
	public List<RowBase> GenerateAlarmInfo(List<RowBase> list, String[] parms, String mn, String dataType){
		int i=0;
		HashMap<String, Double> pollAlarmMap = new HashMap<>();
		
		for(RowBase row : list){
			
			for(String poll:parms){
				String fieldName  = dataType+"_"+poll.toUpperCase();
				Double value = row.getDouble(fieldName);
				
				row.setValue(fieldName+"_ALARM_FLAG", 0);//0表示正常
				
				if(value == null){
					continue;
				}
				
				Double overUp = null;
				Double overDown = null;
				
				if(pollAlarmMap.containsKey(poll+"_alarmUp")){
					overUp = pollAlarmMap.get(poll+"_alarmUp");
				}
				else{
					overUp = RedisHelper.getInstance().getPollAlarmUp(mn, poll);
					i++;
					pollAlarmMap.put(poll+"_alarmUp",overUp);
				}
				
				if(pollAlarmMap.containsKey(poll+"_alarmDown")){
					overDown = pollAlarmMap.get(poll+"_alarmDown");
				}
				else{
					overDown = RedisHelper.getInstance().getPollAlarmDown(mn, poll);
					i++;
					pollAlarmMap.put(poll+"_alarmDown",overDown);
				}
				
				if(overUp != null && value > overUp){
					row.setValue(fieldName+"_ALARM_FLAG", "ALARM_OVER");//表示超标
				}
				
				if(overDown != null && value < overDown){
					row.setValue(fieldName+"_ALARM_FLAG", "ALARM_LESS");//表示小于低限
				}
				
				Double abnormalUp = null;
				Double abnormalDown = null;
				
				if(pollAlarmMap.containsKey(poll+"_abnormalUp")){
					abnormalUp = pollAlarmMap.get(poll+"_abnormalUp");
				}
				else{
					abnormalUp = RedisHelper.getInstance().getPollAbnormalUp(mn, poll);
					i++;
					pollAlarmMap.put(poll+"_abnormalUp",abnormalUp);
				}
				
				if(pollAlarmMap.containsKey(poll+"_abnormalDown")){
					abnormalDown = pollAlarmMap.get(poll+"_abnormalDown");
				}
				else{
					abnormalDown = RedisHelper.getInstance().getPollAbnormalDown(mn, poll);
					i++;
					pollAlarmMap.put(poll+"_abnormalDown",abnormalDown);
				}
				
				if(abnormalUp == null)
				{
					abnormalUp = 99999999999.0;
				}
				
				if(abnormalDown == null)
				{
					abnormalDown = 0.0;
				}
	
				if(value > abnormalUp){
					row.setValue(fieldName, ">" + abnormalUp);
					row.setValue(fieldName+"_ALARM_FLAG", "ODD_OVER");//表示超高异常
				}
				
				if(value < abnormalDown){
					row.setValue(fieldName, "<" + abnormalDown);
					row.setValue(fieldName+"_ALARM_FLAG", "ODD_LESS");//表示超低异常
				}
				
			}
		}
		System.out.println("获取次数："+i);
		return list;
	}

	/**
	 * 配合fixMissData方法，获取下一个时间
	 * 不同业务，不同数据，获选下一个时间的参数不一样
	 * gislin
	 * 2017年4月26日
	 * @param cal
	 * @param waterType
	 * @param dataType
	 * @return
	 */
	public Calendar getNextCalendar(Calendar cal, String waterType, MonitorDataType dataType){
		
		int hourInterval = -1;
		int minuteInterval = -10;
		int dayInterval = -1;
		int monthInterval = -1;
		
		/**
		 * 考虑后续各个专题的时间间隔可能不一样
		 * 预留处理
		 */
		if(waterType.equals("1")){
			hourInterval = -1;
			minuteInterval = -10;
			dayInterval = -1;
			monthInterval = -1;
		}else if(waterType.equals("2")){
			hourInterval = -1;
			minuteInterval = -5;
			dayInterval = -1;
			monthInterval = -1;
		}else if(waterType.equals("4")){
			hourInterval = -1;
			minuteInterval = -5;
			dayInterval = -1;
			monthInterval = -1;
		}
		
		if(dataType.equals(MonitorDataType.hour)){
			cal.add(Calendar.HOUR_OF_DAY, hourInterval);
		}
		else if(dataType.equals(MonitorDataType.minute)){
			cal.add(Calendar.MINUTE, minuteInterval);
		}
		else if(dataType.equals(MonitorDataType.day)){
			cal.add(Calendar.DAY_OF_MONTH, dayInterval);
		}
		else if(dataType.equals(MonitorDataType.month)){
			cal.add(Calendar.MONTH, monthInterval);
		}
		
		return cal;
	}

	/**
	 * 数据缺失留白
	 * gislin
	 * 2017年4月26日
	 * @param historyData
	 * @param waterType 业务类型，不同业务相同数据类型的数据间隔可能不一样，这里作为一个拓展点
	 * @param dataType 
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	public List<RowBase> fixMissData(List<RowBase> historyData, String waterType, MonitorDataType dataType, Date startDate, Date endDate){
		
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		/**
		 * 周期数据、实时数据暂不处理
		 */
		if(dataType == MonitorDataType.cycle ||
				dataType.equals(MonitorDataType.second)){
			return historyData;
		}
		
		/**
		 * 存放数据留白的最终结果
		 */
		List<RowBase> fixedResult = new ArrayList<>();
		Iterator<RowBase> historyDataIterator = historyData.iterator();
		
		/**
		 * 顺序取historyData中的数据时间，以此为基准
		 * 和endCal作比较，判断缺了哪些数据
		 */
		Calendar nextEndCal = Calendar.getInstance();
				
		Calendar startCal = Calendar.getInstance();
		startCal.setTime(startDate);
		
		Calendar endCal = Calendar.getInstance();
		endCal.setTime(endDate);
		endCal.set(Calendar.SECOND, 0);
		
		if(dataType.equals(MonitorDataType.hour)){
			endCal.set(Calendar.MINUTE, 0);
		}
		else if(dataType.equals(MonitorDataType.day)){
			endCal.set(Calendar.MINUTE, 0);
			endCal.set(Calendar.HOUR_OF_DAY, 0);
		}
		else if(dataType.equals(MonitorDataType.month)){
			endCal.set(Calendar.MINUTE, 0);
			endCal.set(Calendar.HOUR_OF_DAY, 0);
			endCal.set(Calendar.DAY_OF_MONTH, 1);//因为月数据表中都是1号，这里设置成1号，便于留白判断
		}
		
		while(!endCal.before(startCal)){
			
			RowBase currentRow = null;
			Date nextEndDataDate = null;
			
			if(historyDataIterator.hasNext()){
				currentRow = historyDataIterator.next();
			}
			/**
			 * 取到第一个日期
			 */
			if(currentRow == null){
				nextEndDataDate = startCal.getTime();
			}
			else{
				nextEndDataDate = currentRow.getDate("DATATIME");
			}
			nextEndCal.setTime(nextEndDataDate);
			/**
			 * 分钟秒设置为0，变成整点数据，方便比较，有些数据时间不是刚好整点
			 */			
			nextEndCal.set(Calendar.SECOND, 0);
			
			if(dataType.equals(MonitorDataType.hour)){
				nextEndCal.set(Calendar.MINUTE, 0);
			}
			else if(dataType.equals(MonitorDataType.day)){
				nextEndCal.set(Calendar.MINUTE, 0);
				nextEndCal.set(Calendar.HOUR_OF_DAY, 0);
			}
			
			if(!endCal.before(nextEndCal) && !endCal.equals(nextEndCal)){
				/**
				 * 如果条件成立，代表有数据空白，插入空数据
				 */
				while(!endCal.before(nextEndCal) && !endCal.equals(nextEndCal)){
					RowBase row = new RowBase();
					row.setValue("DATATIME",new Timestamp(endCal.getTimeInMillis()));
					
					fixedResult.add(row);
					System.out.println("endCal:"+sf.format(endCal.getTime())+",nextEndCal:"+sf.format(nextEndCal.getTime())+",插入");
					endCal = getNextCalendar(endCal, waterType, dataType);
				}
				endCal = getNextCalendar(endCal, waterType, dataType);
				fixedResult.add(currentRow);
				System.out.println("endCal:"+sf.format(endCal.getTime())+",nextEndCal:"+sf.format(nextEndCal.getTime()));
			}
			else{
				/**
				 * 否则直接把当前行加入
				 */
				endCal = getNextCalendar(endCal, waterType, dataType);
				System.out.println("endCal:"+sf.format(endCal.getTime())+",nextEndCal:"+sf.format(nextEndCal.getTime()));
				fixedResult.add(currentRow);
			}			
		}
		//判断fixedResult最后一条数据是否已经存在。//Added by xwei
				boolean flag =false;
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				for(int i=0;i<fixedResult.size();i++) {
					RowBase row = fixedResult.get(i);
					
					if(row!=null) {
						String datatime = fixedResult.get(i).getSafeString("DATATIME");
						try {
							Date date= sdf.parse(datatime);
							datatime = sdf.format(date);
							Date date1 = nextEndCal.getTime();
							String datatime1 = sdf.format(date1);
							if(datatime.equals(datatime1)) {
								flag=true;
							}
						} catch (ParseException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				}
				//如果最后结果不存在最后一条数据，则补充上。
				if(!flag) {
					RowBase row = new RowBase();
					row.setValue("DATATIME",new Timestamp(nextEndCal.getTimeInMillis()));
					fixedResult.add(row);
				}

		return fixedResult;
	}

	/**
	 * 查询历史数据
	 * @param mn 设备mn
	 * @param startDate 开始时间
	 * @param endDate 结束时间
	 * @param tableName 查询的表名称
	 * @param parms 要查询的污染物code
	 * @param dataFields 要查询的字段
	 * @return
	 */
	public MonitorDataModel getHistoryData(String mn, Date startDate, Date endDate, String tableName, String[] parms, String[] dataFields){
		
		long startTime=System.currentTimeMillis();   //获取开始时间
		
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		ParameterSqlModel parmParmSql = SqlUtil.prepareArrayParmAndSql(parms, "parm_name");
		String fieldString="";
		for(String field : dataFields){
			fieldString+=field+",";
		}
		fieldString=fieldString.substring(0,fieldString.length()-1);
		String sql = " select parmname,"+fieldString+",mn,datatime,flag from "+tableName+" t \n "+
				"   	where t.mn = @mn and datatime >= to_date(@start,'yyyy-mm-dd HH24:mi:ss') \n" +
				"			and datatime<=to_date(@end,'yyyy-mm-dd HH24:mi:ss') \n"+
				"			and t.parmname in "+ parmParmSql.getSql()+
				"			order by datatime desc ";
		
		List<GlobalParameter> pc = new ArrayList<>();
		pc.addAll(parmParmSql.getParms());
		pc.add(new GlobalParameter("mn", mn));
		pc.add(new GlobalParameter("start", sf.format(startDate)));
		pc.add(new GlobalParameter("end", sf.format(endDate)));
		
		startTime=System.currentTimeMillis();   //获取开始时间
		List<RowBase> result = DataUtil.getSelectRows(sql, pc);
		long endTime = System.currentTimeMillis(); //获取结束时间
		System.out.println("sql查询时间： "+(endTime-startTime)+"ms");
		
		List<PollutantsModel> pollInfo = getPollInfo(mn, parms);
		
		MonitorDataModel dataModel = new MonitorDataModel();
		dataModel.setData(result);
		dataModel.setPollInfoList(pollInfo);
		dataModel.setParms(parms);
		
		return dataModel;
	}

}
